var t = getApp();

Page({
    data: {
        wrapBox: !0,
        showshow: !1,
        show: !0,
        page: 0,
        activitys: "",
        smallFilePath: "",
        bigFilePath: "",
        laterFlag: !0
    },
    previewImg: function(t) {
        var a = this, e = t.currentTarget.dataset.text;
        console.log(e);
        var i = t.target.dataset.id;
        console.log(i);
        var o = a.data.commonality[e].estimateContentImgBig;
        a.data.commonality[e].estimateContentImgBig[i];
        wx.previewImage({
            current: o[i],
            urls: o
        });
    },
    previewImg1: function(t) {
        var a = this, e = t.target.dataset.id;
        console.log(e);
        var i = a.data.my.estimateContentImgBig;
        a.data.my.estimateContentImgBig[e];
        wx.previewImage({
            current: i[e],
            urls: i
        });
    },
    praise: function(a) {
        var e = this;
        console.log(a);
        var i = a.currentTarget.dataset.index, o = e.data.commonality;
        1 != o[i].voteStatus && (o[i].voteStatus = 1, o[i].praiseCount = o[i].praiseCount + 1, 
        wx.request({
            url: t.globalData.dicc + "public/activity/saveVote",
            data: {
                token: e.data.token,
                userType: 1,
                topicId: a.currentTarget.dataset.id
            },
            method: "POST",
            header: {
                "Content-Type": "application/x-www-form-urlencoded"
            },
            success: function(t) {
                console.log(t.data.data), 200 == t.data.code && (wx.showToast({
                    title: "点赞成功",
                    icon: "none",
                    duration: 1500
                }), e.setData({
                    commonality: o
                }));
            },
            fail: function() {}
        }));
    },
    onLoad: function(a) {
        console.log(a);
        var e = this, i = wx.getStorageSync("log") || "";
        e.setData({
            id: a.id,
            token: i
        }), e.onClick(), wx.getSystemInfo({
            success: function(t) {
                e.setData({
                    height: t.windowHeight
                });
            }
        }), wx.request({
            url: t.globalData.dicc + "ad/get/actTheme",
            data: {
                id: e.data.id
            },
            success: function(t) {
                e.setData({
                    img: t.data.data.activityImg.split("|")
                });
            }
        });
    },
    wrapBox: function(t) {
        this.setData({
            showshow: !0
        });
    },
    alet: function(t) {
        this.setData({
            showshow: !1
        });
    },
    onShow: function() {
        var a = this;
        wx.login({
            success: function(e) {
                var i = e.code;
                wx.request({
                    url: t.globalData.httpLogin + "doctor/code",
                    data: {
                        code: i,
                        token: wx.getStorageSync("log") || ""
                    },
                    success: function(t) {
                        console.log(t), a.setData({
                            token: t.data.data.token
                        });
                        var e = t.data.data.authRealName, i = t.data.data.failReason;
                        0 == e ? a.setData({
                            showshow: !0,
                            texttext: "未创建工作室",
                            texttext1: "您还没有属于自己的工作室，暂时无法使用此功能，通过认证才能完成工作室创建",
                            nameText: "去认证",
                            wrapBox: !0,
                            bij: "/assets/images/renzheng.png"
                        }) : 1 == e ? a.setData({
                            showshow: !0,
                            texttext: "资格审核中",
                            texttext1: "资格审核中，请稍后",
                            nameText: "修改认证信息",
                            wrapBox: !0,
                            bij: "/assets/images/renzheng.png"
                        }) : 3 == e ? a.setData({
                            showshow: !0,
                            texttext: "认证失败",
                            texttext1: i || "认证未通过",
                            nameText: "重新认证",
                            wrapBox: !0,
                            bij: "/assets/images/renzheng.png"
                        }) : 2 == e && a.setData({
                            showshow: !1,
                            wrapBox: !1,
                            bij: "/assets/images/renzheng1.png",
                            activityShowFlag: !0
                        });
                    }
                });
            }
        });
    },
    onClick: function(a) {
        var e = this;
        wx.request({
            url: t.globalData.dicc + "public/activity/listActivity/0/10/" + e.data.token,
            success: function(t) {
                if (console.log(t.data), null == t.data.data.businessActivityBbsTopicVO ? e.setData({
                    show: !1
                }) : e.setData({
                    show: !0
                }), null != t.data.data.businessActivityBbsTopicVO) {
                    var a = t.data.data.businessActivityBbsTopicVO;
                    console.log(a.estimateContentImgSmll.length), 1 == a.estimateContentImgSmll.length ? e.setData({
                        activitys: "activity-for-img1"
                    }) : 2 == a.estimateContentImgSmll.length ? e.setData({
                        activitys: "activity-for-img2"
                    }) : 3 == a.estimateContentImgSmll.length && e.setData({
                        activitys: "activity-for-img3"
                    });
                }
                e.setData({
                    my: t.data.data.businessActivityBbsTopicVO,
                    commonality: t.data.data.listBusinessActivityBbsTopicVO
                });
            }
        });
    },
    lower: function() {
        var a = this, e = a.data.page;
        e++, a.setData({
            page: e
        });
        var i, o = a.data.commonality;
        wx.request({
            url: t.globalData.dicc + "public/activity/listActivity/" + e + "/10/" + a.data.token,
            data: {},
            success: function(t) {
                if (200 == t.data.code) {
                    var e = t.data.data.listBusinessActivityBbsTopicVO;
                    if (i = o.concat(e), t.data.data.listBusinessActivityBbsTopicVO.length == []) return wx.showToast({
                        title: "已到达底部",
                        icon: "none",
                        duration: 3e3
                    }), !1;
                    wx.showLoading({
                        title: "加载中",
                        icon: "loading"
                    }), setTimeout(function() {
                        a.setData({
                            commonality: i
                        }), wx.hideLoading();
                    }, 1500);
                }
            }
        });
    },
    newclick: function(t) {
        this.setData({
            laterFlag: !1
        });
    },
    onShareAppMessage: function() {
        return {
            title: "传递微笑",
            path: "/pages/index/index?flag=4&id=" + this.data.id
        };
    },
    chooseImg: function() {
        var t = this;
        wx.chooseImage({
            count: 3,
            sizeType: [ "original", "compressed" ],
            sourceType: [ "album", "camera" ],
            success: function(a) {
                console.log(a), t.laterFun();
                var e = a.tempFilePaths;
                t.setData({
                    tempFilePaths: e
                });
                var i = e.length;
                wx.showLoading({
                    title: "发布中..."
                }), t.activityChooseImg(e, 0, i, t);
            }
        });
    },
    activityChooseImg: function(a, e, i, o) {
        var s = this, n = s.data.smallFilePath, c = s.data.bigFilePath;
        wx.uploadFile({
            url: t.globalData.dicc + "public/activity/uploadImage",
            method: "POST",
            header: {
                "content-type": "multipart/form-data"
            },
            filePath: a[e],
            name: "file",
            success: function(l) {
                var d = JSON.parse(l.data).data;
                if ("" == n ? (n = d.smallFilePath, c = d.bigFilepath) : (n += "|" + d.smallFilePath, 
                c += "|" + d.bigFilepath), s.setData({
                    smallFilePath: n,
                    bigFilePath: c
                }), ++e == i) {
                    var g = {
                        token: s.data.token,
                        activityId: s.data.id,
                        contentImgSmll: s.data.smallFilePath,
                        contentImgBig: s.data.bigFilePath
                    };
                    wx.request({
                        url: t.globalData.dicc + "public/activity/saveActivityTopic",
                        method: "POST",
                        header: {
                            "content-type": "application/x-www-form-urlencoded"
                        },
                        data: g,
                        success: function(t) {
                            console.log(t), 200 == t.data.code ? (s.onClick(), wx.showToast({
                                title: "发布成功",
                                icon: "none",
                                duration: 2e3
                            })) : wx.showToast({
                                title: "系统繁忙，请稍后重试",
                                icon: "none",
                                duration: 2e3
                            });
                        },
                        fail: function(a) {
                            t.showToast();
                        },
                        complete: function() {
                            wx.hideLoading();
                        }
                    });
                } else s.activityChooseImg(a, e, i, o);
            },
            fail: function(a) {
                console.log(a), t.showToast();
            },
            complete: function() {}
        });
    },
    laterFun: function() {
        this.setData({
            laterFlag: !0
        });
    }
});